WW.Char = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"} -- random detail


--################# Recieve Notify @KP3/Prefanatic
function RecieveNotify(UCMD)
	surface.SetFont("NotifyFont")
    NotifyMessage = UCMD:ReadString()
	NotifyTime = UCMD:ReadShort()
	NotifyDeath = UCMD:ReadBool() if NotifyDeath then NoteDeath = "and is dead!" else NoteDeath = "and isn't dead!" end
	local Time = CurTime()
	local Fade = 0.5
	Detail1 = table.Random(WW.Char) .. table.Random(WW.Char)
	Detail2 = table.Random(WW.Char) .. table.Random(WW.Char)
	RealMessage = string.upper(NotifyMessage)
	if !NotifyDeath then RunConsoleCommand("play", table.Random(WW.Sounds.Notify)) end
	if LocalPlayer():GetNWBool("testing") and !NotifyDeath then Say(NotifyMessage) end
	
	print("Recieved notification!  Message: " .. NotifyMessage .. " Time up: " .. NotifyTime .. " " .. NoteDeath)
	
	local function DisplayNotify()	
		local alpha = 255
		local DoomTime = CurTime() - Time
		
		if DoomTime > NotifyTime then 
			hook.Remove( "HUDPaint", "NotifyDraw" )	
			ResetNotify()
			return
		end
		
		if Fade - DoomTime > 0 then
			alpha = (Fade - DoomTime) / Fade
			alpha = 1 - alpha
			alpha = alpha * 255
		end
		
		if NotifyTime - DoomTime < Fade then 
			alpha = (NotifyTime - DoomTime) / Fade
			alpha = alpha * 255
		end		
		alpha = alpha
		
		draw.RoundedBox(6, (ScrW() / 2) - (((string.len(RealMessage) * FontResize) * 18) / 2), ScrH() / 2 - 350, (string.len(RealMessage) * FontResize) * 18, 50, Color(0, 0, 0, alpha / 2))
		
		draw.DrawText(RealMessage, "NotifyFont", ScrW() / 2, ScrH() / 2 - 335, Color(255,255,255,alpha), 1) 
		draw.DrawText(Detail1, "DetailFont", ScrW() / 2 - ((string.len(RealMessage)* FontResize) * 7), ScrH() / 2 - 335, Color(255,255,255,alpha), 1)
		draw.DrawText(Detail2, "DetailFont", ScrW() / 2 + ((string.len(RealMessage)* FontResize) * 7), ScrH() / 2 - 335, Color(255,255,255,alpha), 1)

	end
	
	hook.Add("HUDPaint", "NotifyDraw", DisplayNotify)
end
usermessage.Hook("_Notify", RecieveNotify)

function Say( msg )

	if !SpeakLoaded then return false end
	
	gspeak.Say( msg )
	print("Said: " .. msg)
	
end

--################# Reset Notify Vars @Prefanatic
function ResetNotify()
	NotifyMessage = ""
	NotifyTime = 0
	DoomTime = 0
end

function RecieveSound(UCMD)

	local Sound = UCMD:ReadString()
	
	print("Recieved sound, playing " .. Sound .. "!")
	RunConsoleCommand("play", Sound)
	--LocalPlayer():PlaySound( Sound )
	
end
usermessage.Hook("_Sound", RecieveSound)

function RecievePrint(UCMD)

	local Print = UCMD:ReadString()
	
	print(Print)
	
end
usermessage.Hook("_DebugPrint", RecievePrint)

--################# Client to Server Function Caller @aVoN
function CallServerFunction(func,...)
	RunConsoleCommand(LocalPlayer():GetNWString("randcommand"),func,...);
end

function ReserveDataFromServer(handler, id, encoded, decoded)
	upgrades = decoded
end
datastream.Hook("UpgradeTable", ReserveDataFromServer)

function CheckforPack(UM)
	
	local pack = file.Exists("../addons/WW_Content_Pack/info.txt")
	if pack then CallServerFunction( "SetHasPack", "true" ) else CallServerFunction( "SetHasPack", "false" ) end
	
end
usermessage.Hook("_CheckContent", CheckforPack)

function PrintPackInfo(UM)

	print("\n\nYou do not have the World Wars content pack!\nPlease, visit " .. WW.Content.HTTP .. " to download it.\nAfter it is downloaded, please extract it into your addons folder.\nIt should look like the following:\ngarrysmod/addons/WW_Content_Pack/\n\n")
	
end
usermessage.Hook("_PrintPack", PrintPackInfo)